package com.usian.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemDesc;
import com.usian.service.ItemService;
import com.usian.utils.ItemCatResult;
import com.usian.utils.PageResult;
import com.usian.utils.PreUpdate;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/findItemById")
    public TbItem findItemById(@RequestParam Long id){
        TbItem tbItem = itemService.findItemById(id);
        return tbItem;
    }

    @RequestMapping("/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(@RequestParam Integer page, @RequestParam Integer rows){
        return itemService.selectTbItemAllByPage(page,rows);
    }

    @RequestMapping("/insertTbItem")
    public Boolean insertTbItem(@RequestBody TbItem tbItem, @RequestParam String desc, @RequestParam String itemParams){
        return itemService.insertTbItem(tbItem,desc,itemParams);
    }

    @RequestMapping("deleteItemById")
    public Boolean deleteItemById(@RequestParam String itemId){
      return itemService.deleteItemById(itemId);
    };

    @RequestMapping("preUpdateItem")
    public PreUpdate preUpdateItem(Long itemId){
        return itemService.preUpdateItem(itemId);
    }

    @RequestMapping("updateTbItem")
    public Boolean updateTbItem(@RequestBody TbItem tbItem, @RequestParam String desc, @RequestParam String itemParams){
        return itemService.updateTbItem(tbItem,desc,itemParams);
    }

    @RequestMapping("selectItemDescByItemId")
    TbItemDesc selectItemDescByItemId(@RequestParam Long itemId){
        return itemService.selectItemDescByItemId(itemId);
    }




}
